home *** CD-ROM | disk | FTP | other *** search
- *** old\fmath.c
- --- fmath.c
- **************
- *** 26,27
- #if LATTICE
- #include <error.h>
- --- 26,30 -----
- #if LATTICE
- + #ifdef __GNUC__
- + #include <errno.h>
- + #else
- #include <error.h>
- **************
- *** 27,28
- #include <error.h>
- #else /* LATTICE */
- --- 30,32 -----
- #include <error.h>
- + #endif
- #else /* LATTICE */
- *** old\fsys.c
- --- fsys.c
- **************
- *** 427,428
- mode[1] = '+';
- mode[2] = untranslated ? 'b' : 'a';
- --- 427,431 -----
- mode[1] = '+';
- + #ifdef __GNUC__
- + mode[2] = untranslated ? 'b' : '\0';
- + #else
- mode[2] = untranslated ? 'b' : 'a';
- **************
- *** 428,429
- mode[2] = untranslated ? 'b' : 'a';
- }
- --- 431,433 -----
- mode[2] = untranslated ? 'b' : 'a';
- + #endif
- }
- **************
- *** 429,430
- }
- else mode[1] = untranslated ? 'b' : 'a';
- --- 433,437 -----
- }
- + #ifdef __GNUC__
- + else mode[1] = untranslated ? 'b' : '\0';
- + #else
- else mode[1] = untranslated ? 'b' : 'a';
- **************
- *** 430,431
- else mode[1] = untranslated ? 'b' : 'a';
- #endif /* ATARI_ST */
- --- 437,439 -----
- else mode[1] = untranslated ? 'b' : 'a';
- + #endif
- #endif /* ATARI_ST */
- *** old\getch.c
- --- getch.c
- **************
- *** 0,0
- --- 1,28 -----
- + #include <osbind.h>
- +
- + int getch()
- + {
- + int c;
- +
- + c = Crawcin() & 0xFF;
- + return(c);
- + }
- +
- + int putch(c)
- + int c;
- + {
- + Cconout(c);
- + return(c);
- + }
- +
- + int getche()
- + {
- + int c;
- +
- + return (putch(c = getch()));
- + }
- +
- + int kbhit()
- + {
- + return(Cconis());
- + }
- *** old\imain.c
- --- imain.c
- **************
- *** 18,20
- hidden novalue env_err Params((char *msg,char *name,char *val));
- !
- /*
- --- 18,22 -----
- hidden novalue env_err Params((char *msg,char *name,char *val));
- ! #if ATARI_ST
- ! hidden novalue ST_error Params((char *msg));
- ! #endif
- /*
- **************
- *** 266,268
-
- ! if (!argc)
- error("no icode file specified");
- --- 268,273 -----
-
- ! if (!argc) {
- ! #if ATARI_ST
- ! ST_error("no icode file specified");
- ! #else
- error("no icode file specified");
- **************
- *** 268,269
- error("no icode file specified");
- /*
- --- 273,276 -----
- error("no icode file specified");
- + #endif /* ATARI_ST */
- + }
- /*
- **************
- *** 610,612
- #endif /* TallyOpt */
- !
- /*
- --- 617,623 -----
- #endif /* TallyOpt */
- ! #if ATARI_ST
- ! case 't':
- ! k_trace = -1;
- ! break;
- ! #endif /* ATARI_ST */
- /*
- **************
- *** 657,659
-
- ! #if ATARI_ST || MSDOS || OS2 || VMS
- dup2(fileno(stdout),fileno(stderr));
- --- 668,673 -----
-
- ! #if ATARI_ST
- ! #ifdef __GNUC__
- ! ST_error("redirection of stderr to stdout not supported");
- ! #else
- dup2(fileno(stdout),fileno(stderr));
- **************
- *** 659,661
- dup2(fileno(stdout),fileno(stderr));
- ! #endif /* ATARI_ST || MSDOS || OS2 ... */
-
- --- 673,679 -----
- dup2(fileno(stdout),fileno(stderr));
- ! #endif
- ! #endif /* ATARI_ST */
- ! #if MSDOS || OS2 || VMS
- ! dup2(fileno(stdout),fileno(stderr));
- ! #endif /* MSDOS || OS2 ... */
-
- **************
- *** 721,722
- extern struct astkblk *alcactiv();
-
- --- 739,743 -----
- extern struct astkblk *alcactiv();
- + #if ATARI_ST
- + int trace_flag = k_trace;
- + #endif /* ATARI_ST */
-
- **************
- *** 831,832
- datainit();
-
- --- 852,857 -----
- datainit();
- + #if ATARI_ST
- + if (-1 == trace_flag)
- + k_trace = trace_flag;
- + #endif /* ATARI_ST */
-
- **************
- *** 837,838
- if (!name)
- error("no interpreter file supplied");
- --- 862,866 -----
- if (!name)
- + #if ATARI_ST
- + ST_error("no interpreter file supplied");
- + #else
- error("no interpreter file supplied");
- **************
- *** 838,840
- error("no interpreter file supplied");
- !
- /*
- --- 866,868 -----
- error("no interpreter file supplied");
- ! #endif
- /*
- **************
- *** 900,902
-
- !
- k_trace = hdr.trace;
- --- 928,932 -----
-
- ! #if ATARI_ST
- ! if (-1 != k_trace)
- ! #endif /* ATARI_ST */
- k_trace = hdr.trace;
- **************
- *** 1363,1364
-
- /*
- --- 1393,1400 -----
-
- + hidden novalue ST_error(s)
- + char *s;
- + {
- + fprintf(stderr, "usage: iconx %s\n", Usage);
- + error(s);
- + }
- /*
- *** old\makefile
- --- makefile
- **************
- *** 0,0
- --- 1,158 -----
- + CC=gcc
- + CFLAGS=-O -fstrength-reduce -fcombine-regs -fomit-frame-pointer
- + LFLAGS=-x
- + OBJS= extcall.o fconv.o fmath.o fmemmon.o fmisc.o fscan.o fstr.o fstranl.o \
- + fstruct.o fsys.o fxtra.o idata.o imain.o interp.o invoke.o lmisc.o \
- + lrec.o lscan.o oarith.o oasgn.o ocat.o ocomp.o omisc.o oref.o oset.o \
- + ovalue.o rcomp.o rconv.o rdebug.o rdefault.o rlargint.o rdoasgn.o \
- + rlocal.o rmemmgt.o rmisc.o rstruct.o rsys.o rswitch.o
- +
- + COBJS= ..\common\long.o ..\common\memory.o ..\common\time.o
- +
- + LIBS=-lpml
- +
- + PGM=iconx.ttp
- +
- + all: $(PGM)
- +
- + $(PGM): $(OBJS) $(COBJS)
- + $(CC) $(CFLAGS) -o $(PGM) $(OBJS) $(COBJS) $(LIBS) $(LFLAGS)
- + toglclr $(PGM) # for TOS 1.4
- +
- + clean:
- + $(RM) $(OBJS)
- +
- + ####
- + extcall.o : extcall.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + fconv.o : fconv.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + fmath.o : fmath.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + fmemmon.o : fmemmon.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + fmisc.o : fmisc.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + fscan.o : fscan.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + fstr.o : fstr.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + fstranl.o : fstranl.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + fstruct.o : fstruct.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + fsys.o : fsys.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + fxtra.o : fxtra.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + idata.o : idata.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + imain.o : imain.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h ..\h\version.h \
- + ..\h\header.h ..\h\opdefs.h
- + interp.o : interp.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h ..\h\opdefs.h
- + invoke.o : invoke.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + istart.o : istart.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + lmisc.o : lmisc.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h ..\h\keyword.h \
- + ..\h\version.h
- + lrec.o : lrec.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + lscan.o : lscan.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + oarith.o : oarith.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + oasgn.o : oasgn.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + ocat.o : ocat.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + ocomp.o : ocomp.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + omisc.o : omisc.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + oref.o : oref.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + oset.o : oset.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + ovalue.o : ovalue.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + rcomp.o : rcomp.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + rconv.o : rconv.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + rdebug.o : rdebug.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h ..\h\opdefs.h
- + rdefault.o : rdefault.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + rdoasgn.o : rdoasgn.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + rlargint.o : rlargint.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + rlocal.o : rlocal.c getch.c system.c ..\h\config.h ..\h\define.h \
- + ..\h\proto.h ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + rmemmgt.o : rmemmgt.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h rmemexp.c
- + rmisc.o : rmisc.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + rstruct.o : rstruct.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + rswitch.o : rswitch.s
- + rsys.o : rsys.c ..\h\config.h ..\h\define.h ..\h\proto.h \
- + ..\common\cproto.h ..\h\rt.h ..\h\cpuconf.h \
- + ..\h\memsize.h rproto.h ..\h\fdefs.h ..\h\odefs.h
- + #
- + ..\common\long.o : ..\common\long.c ..\h\config.h \
- + ..\h\define.h ..\h\proto.h ..\common\cproto.h ..\h\cpuconf.h
- + pushd ..\common
- + make long.o
- + popd
- + ..\common\memory.o : ..\common\memory.c ..\h\config.h \
- + ..\h\define.h ..\h\proto.h ..\common\cproto.h
- + pushd ..\common
- + make memory.o
- + popd
- + ..\common\time.o : ..\common\time.c ..\h\config.h \
- + ..\h\define.h ..\h\proto.h ..\common\cproto.h
- + pushd ..\common
- + make time.o
- + popd
- *** old\rconv.c
- --- rconv.c
- **************
- *** 554,555
- #if AMIGA || ATARI_ST || MSDOS || UNIX || VMS
- gcvt(n, Precision, s);
- --- 554,561 -----
- #if AMIGA || ATARI_ST || MSDOS || UNIX || VMS
- + #ifdef __GNUC__
- + (void)sprintf(s,"%.*g", Precision, n);
- + if (('-' == *s) && ('0' == s[1])) {
- + (void)memcpy(s + 1, s + 2, strlen(s + 1)); /* add one for '\0' */
- + }
- + #else
- gcvt(n, Precision, s);
- **************
- *** 555,556
- gcvt(n, Precision, s);
- #endif /* AMIGA || ATARI_ST || ... */
- --- 561,563 -----
- gcvt(n, Precision, s);
- + #endif
- #endif /* AMIGA || ATARI_ST || ... */
- *** old\rlocal.c
- --- rlocal.c
- **************
- *** 101,102
-
- long _STACK = 10240;
- --- 101,108 -----
-
- + #ifdef __GNUC__
- + #include <osbind.h>
- + extern long _initial_stack = 3L; /* grab 3/4 of available memory */
- + #include "getch.c"
- + #include "system.c"
- + #else
- long _STACK = 10240;
- **************
- *** 135,136
- }
-
- --- 141,143 -----
- }
- + #endif
-
- **************
- *** 136,138
-
- -
- weekday(day,month,year) /* find day of week from */
- --- 143,144 -----
-
- weekday(day,month,year) /* find day of week from */
- **************
- *** 155,156
-
- time(ptime) /* return value of millisecond timer */
- --- 161,165 -----
-
- + #ifdef __GNUC__
- + atime(ptime) /* return value of millisecond timer */
- + #else
- time(ptime) /* return value of millisecond timer */
- **************
- *** 156,157
- time(ptime) /* return value of millisecond timer */
- int *ptime;
- --- 165,167 -----
- time(ptime) /* return value of millisecond timer */
- + #endif
- int *ptime;
- **************
- *** 161,162
-
- ssp = gemdos(0x20,0); /* enter supervisor mode */
- --- 171,176 -----
-
- +
- + #ifdef __GNUC__
- + ssp = Super(0L); /* enter supervisor mode */
- + #else
- ssp = gemdos(0x20,0); /* enter supervisor mode */
- **************
- *** 162,163
- ssp = gemdos(0x20,0); /* enter supervisor mode */
- tmp = *tmr * 5; /* get millisecond timer */
- --- 176,178 -----
- ssp = gemdos(0x20,0); /* enter supervisor mode */
- + #endif
- tmp = *tmr * 5; /* get millisecond timer */
- **************
- *** 163,164
- tmp = *tmr * 5; /* get millisecond timer */
- ssp = gemdos(0x20,ssp); /* enter programmer mode */
- --- 178,182 -----
- tmp = *tmr * 5; /* get millisecond timer */
- + #ifdef __GNUC__
- + ssp = Super(ssp); /* enter programmer mode */
- + #else
- ssp = gemdos(0x20,ssp); /* enter programmer mode */
- **************
- *** 164,166
- ssp = gemdos(0x20,ssp); /* enter programmer mode */
- !
- if(ptime != NULL)
- --- 182,184 -----
- ssp = gemdos(0x20,ssp); /* enter programmer mode */
- ! #endif
- if(ptime != NULL)
- **************
- *** 180,181
-
- return((lsbrk((long) (l - m)) == 0) ? -1 : 0);
- --- 198,202 -----
-
- + #ifdef __GNUC__
- + return(-(lsbrk((long) (l - m)) == -1L));
- + #else
- return((lsbrk((long) (l - m)) == 0) ? -1 : 0);
- **************
- *** 181,182
- return((lsbrk((long) (l - m)) == 0) ? -1 : 0);
- }
- --- 202,204 -----
- return((lsbrk((long) (l - m)) == 0) ? -1 : 0);
- + #endif
- }
- *** old\rswitch.s
- --- rswitch.s
- **************
- *** 0,0
- --- 1,57 -----
- + |-------------------------------------------------------------------------
- + | Context switch for Atari ST Icon
- + |-------------------------------------------------------------------------
- + |
- + | ======== SP (a7) -> |-------------------| Low
- + | expression evaluation | temporaries |
- + | |-------------------|
- + | addressed as negative | auto data items |
- + | offsets from FP | . . . |
- + | ======== FP (a6) -> |-------------------|
- + | called routine pushes | caller's saved FP |
- + | |-------------------|
- + | pushed by jsr | return address |
- + | |-------------------|
- + | first argument is | arguments |
- + | a6 plus 8 bytes | . . . |
- + | old SP value -----> |-------------------| High
- + |
- + |-------------------------------------------------------------------------
- + .text | control section for instructions
- + .globl _coswitch
- + .globl _interp
- + .globl _syserr
- + | * * * * * * * * * * * * * * * * * * *
- + _coswitch:
- + link a6,#0 | push frame pointer & allocate no locals
- + movel a6@(8),a0 | a0 = address of old_cs
- + movel a6@(12),a1 | a1 = address of new_cs
- + movel a7,a0@ | store stack pointer in old_cs
- + moveml d2-d7/a2-a6,a0@(4) | store needed registers in old_cs
- + movel a1@,a7 | load stack pointer from new_cs
- + tstl a6@(16) | if(first == 0) {
- + bne nofirst
- + moveq #0,d0 | zero return value
- + movel d0,a6 | zero frame pointer
- + movel d0,sp@- | push two zero arguments
- + movel d0,sp@- | for interp()
- + jsr _interp | call interp()
- + addql #8,a7 | remove interp() args from stack
- + pea mesg | push argument for syserr()
- + jsr _syserr | call syserr()
- + | * * * * * * * * * * * * * * * * * * *
- + | Following instructions not needed because syserr() never returns *
- + | *
- + | addql #4,a7 | remove syserr() args from stack *
- + | bra done } else *
- + | * * * * * * * * * * * * * * * * * * *
- + nofirst:
- + moveml a1@(4),d2-d7/a2-a6 | restore preserved regs from new_cs
- + | * * * * * * * * * * * * * * * * * * *
- + done:
- + unlk a6 | restore frame pointer from stack
- + rts | return to calling program
- + | * * * * * * * * * * * * * * * * * * *
- + .data | control section for initialized statics
- + mesg: .asciz "interp() returned in coswitch"
- +
- *** old\system.c
- --- system.c
- **************
- *** 0,0
- --- 1,106 -----
- + #include <osbind.h>
- + #include <stdio.h>
- + #include <string.h>
- + #include <basepage.h>
- + #ifdef __GNUC__
- + #include <process.h>
- + #define ERROR 2
- + #endif
- +
- + /** #define DEBUG **/
- + #ifdef DEBUG
- + #define _COOKIE(x) puts(x);putchar('\n')
- + #endif
- +
- + static parse_args(cmdln, argv)
- + char *cmdln;
- + register char *argv[];
- + {
- + register char *p;
- + static char delim[] = " \t\r\n";
- +
- + if(p = strtok(cmdln, delim))
- + {
- + do
- + {
- + *argv++ = p;
- + }
- + while(p = strtok(NULL, delim));
- + }
- + }
- +
- + #ifdef __GNUC__
- + static volatile long savearea[15];
- + #endif
- +
- + int system(command)
- + register char *command;
- + {
- + register char *p;
- + register int (*shell)();
- + char rv[2];
- + char cmdln[1024];
- + char *args[64];
- + char *getenv();
- +
- + if(!command)
- + return(ERROR);
- +
- + /* get _shell_p value */
- + p = (char *) Super(0L);
- + shell = (int (*)()) *((long *) 0x4F6L);
- + Super(p);
- +
- + /* validate _shell_p */
- + if((shell) && /* Shell available. */
- + (((long) shell) < ((long) _base)) && /* Reasonable shell pointer. */
- + (strncmp((char *)shell, "PATH", 4))) /* Not corrupted */
- + {
- + #ifdef __GNUC__
- + int ret;
- + #endif
- + /* execute the command */
- + #ifdef DEBUG
- + _COOKIE("system: using _shell_p");
- + printf("'shell' got value 0x%08lx\n", (long)shell);
- + #endif
- + /* a bit of paranoia caused by some misbehaving programs */
- + #ifdef __GNUC__
- + asm("moveml d1-d7/a0-a7,_savearea");
- + ret = (*shell)(command);
- + asm("moveml _savearea,d1-d7/a0-a7");
- + return (ret);
- + #else
- + return ((*shell)(command));
- + #endif
- + }
- +
- + strcpy(cmdln, command); /* copy the command line for parsing */
- +
- + if((p = getenv("SHELL")) && (*p)) /* SHELL= variable? */
- + {
- + args[0] = p;
- + parse_args(cmdln, (args + 1));
- + #ifdef DEBUG
- + _COOKIE("system: executing SHELL");
- + _COOKIE(p);
- + #endif
- + }
- + else /* attempt to find first token as a program on the path */
- + {
- + parse_args(cmdln, args);
- + p = args[0];
- + #ifdef DEBUG
- + _COOKIE("system: directly executing program");
- + _COOKIE(p);
- + #endif
- + }
- +
- + #ifdef __GNUC__
- + return spawnvp(0, p, args);
- + #else
- + forkvpe(p, args, NULL);
- + wait(rv);
- + return((rv[1] == 0) ? rv[0] : rv[1]);
- + #endif
- + }
-